package top.zywork.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.zywork.common.BeanUtils;
import top.zywork.dao.RanksUserDAO;
import top.zywork.dos.RanksUserDO;
import top.zywork.dto.RanksUserDTO;
import top.zywork.service.AbstractBaseService;
import top.zywork.service.RanksUserService;
import top.zywork.vo.RanksUserVO;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * RanksUserServiceImpl服务接口实现类<br/>
 *
 * 创建于2020-05-13<br/>
 *
 * @author http://zywork.top 危锦辉
 * @version 1.0
 */
@Service(value = "ranksUserService")
public class RanksUserServiceImpl extends AbstractBaseService implements RanksUserService {

    private RanksUserDAO ranksUserDAO;

    @Autowired
    public void setRanksUserDAO(RanksUserDAO ranksUserDAO) {
        super.setBaseDAO(ranksUserDAO);
        this.ranksUserDAO = ranksUserDAO;
    }

    @PostConstruct
    public void init() {
        super.init(RanksUserDO.class, RanksUserDTO.class);
    }

    @Override
    public RanksUserVO validUserSignUp(Long userId) {
        List<Object> objectList = ranksUserDAO.validUserSignUp(userId);
        if (objectList.isEmpty()) {
            return null;
        }
        return BeanUtils.copy(objectList.get(0), RanksUserVO.class);
    }

    @Override
    public int cancelSignUp(Long id) {
        return ranksUserDAO.cancelSignUp(id);
    }

    @Override
    public List<RanksUserVO> getByActivityId(Long activityId) {
        List<Object> objectList = ranksUserDAO.getByActivityId(activityId);
        if (objectList.isEmpty()) {
            return null;
        }
        List<RanksUserVO> ranksUserVOList = BeanUtils.copy(objectList, RanksUserVO.class);
        return ranksUserVOList;
    }
}